home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / PRINTER.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  11KB  |  443 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. //----------------------------------------------------------------------------
  8. #if !defined(OWL_PRINTER_H)
  9. #define OWL_PRINTER_H
  10.  
  11. #if !defined(OWL_DIALOG_H)
  12. # include <owl/dialog.h>
  13. #endif
  14. #if !defined(OWL_PRINTDIA_H)
  15. # include <owl/printdia.h>
  16. #endif
  17. #include <owl/printer.rh>
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. class _OWLCLASS TPrintDC;
  24.  
  25. // Generic definitions/compiler options (eg. alignment) preceeding the 
  26. // definition of classes
  27. #include <services/preclass.h>
  28.  
  29. //
  30. // class TPrinterAbortDlg
  31. // ~~~~~ ~~~~~~~~~~~~~~~~
  32. class _OWLCLASS TPrinterAbortDlg : public TDialog {
  33.   public:
  34.     TPrinterAbortDlg(TWindow* parent, TResId resId, const char far* title,
  35.                      const char far* device, const char far* port,
  36.                      HDC prnDC = HDC(-1));
  37.  
  38.   protected:
  39.     void     SetupWindow();
  40.     void     CmCancel();
  41.  
  42.     HDC      PrnDC;              // Device context to print on
  43.  
  44.   DECLARE_RESPONSE_TABLE(TPrinterAbortDlg);
  45. };
  46.  
  47. //
  48. // TPrintout banding flags
  49. //
  50. enum TPrintoutFlags {
  51.   pfGraphics = 0x01,     // Current band accepts graphics
  52.   pfText     = 0x02,     // Current band accepts text
  53.   pfBoth     = (pfGraphics|pfText)
  54. };
  55.  
  56. //
  57. // class TPrintout
  58. // ~~~~~ ~~~~~~~~~
  59. // TPrintout represents the physical printed document which is to sent to a
  60. // printer to be printed. TPrintout does the rendering of the document onto the
  61. // printer. For every document, or document type, a corresponding TPrintout
  62. // class should be created.
  63. //
  64. class _OWLCLASS TPrintout : public TStreamableBase {
  65.   public:
  66.     TPrintout(const char far* title);
  67.     virtual ~TPrintout();
  68.  
  69.     virtual void    SetPrintParams(TPrintDC* dc, TSize pageSize);
  70.     virtual void    GetDialogInfo(int& minPage,     int& maxPage,
  71.                                   int& selFromPage, int& selToPage);
  72.     virtual void    BeginPrinting();
  73.     virtual void    BeginDocument(int startPage, int endPage, uint flags);
  74.     virtual bool    HasPage(int pageNumber);
  75.     virtual void    PrintPage(int page, TRect& rect, uint flags);
  76.     virtual void    EndDocument();
  77.     virtual void    EndPrinting();
  78.  
  79.     // Accessors to data members of printout object
  80.     //
  81.     TSize           GetPageSize() const;
  82.     const char far* GetTitle() const;
  83.     bool            WantBanding() const;
  84.     void            SetBanding(bool banding=true);
  85.     bool            WantForceAllBands() const;
  86.     void            SetForceAllBands(bool force=true);
  87.     TPrintDC*       GetPrintDC();
  88.  
  89.   protected:
  90.     void            SetTitle(const char far* title);
  91.     void            SetPrintDC(TPrintDC* dc);
  92.     void            SetPageSize(const TSize& pagesize);
  93.  
  94.   protected_data:
  95.     char far*       Title;         // The title of this printout.
  96.     bool            Banding;       // Whether to use banding if available
  97.     bool            ForceAllBands; // Flag to work around some printers
  98.     TPrintDC*       DC;            // Ptr to DC create&owned by our TPrinter
  99.     TSize           PageSize;      // Dimensions of the printout page
  100.  
  101.   private:
  102.     // Hidden to prevent accidental copying or assignment
  103.     //
  104.     TPrintout(const TPrintout&);
  105.     TPrintout& operator =(const TPrintout&);
  106.  
  107.   DECLARE_STREAMABLE(_OWLCLASS, TPrintout, 1);
  108. };
  109.  
  110. //
  111. // class TPrinter
  112. // ~~~~~ ~~~~~~~~
  113. // TPrinter represent the physical printer device.  To print a TPrintout,
  114. // send the TPrintout to the TPrinter's Print function.
  115. //
  116. class _OWLCLASS TPrinter: public TStreamableBase {
  117.   public:
  118.     TPrinter(TApplication* app = 0);
  119.     virtual ~TPrinter();
  120.  
  121.     virtual void     ClearDevice();
  122.     virtual void     Setup(TWindow* parent);
  123.     virtual bool     Print(TWindow* parent, TPrintout& printout, bool prompt);
  124.     virtual void     ReportError(TWindow* parent, TPrintout& printout);
  125.  
  126.     TPrintDialog::TData& GetSetup();
  127.  
  128.     static void      SetUserAbort(HDC abortDC = HDC(-1));
  129.     static HDC       GetUserAbort();
  130.  
  131.     // Accessors to protected state data
  132.     //
  133.     int              GetError();
  134.     void             SetError(int error);
  135.  
  136.     TPrintDialog::TData* GetData();
  137.     void             SetData(TPrintDialog::TData* data);
  138.  
  139.     TApplication*    GetApplication();
  140.     void             SetApplication(TApplication* app);
  141.  
  142.     bool             GetUseBandInfo() const;
  143.     void             SetUseBandInfo(bool usebandinfo);
  144.  
  145.     uint             GetFlags() const;
  146.     void             SetFlags(uint flags);
  147.  
  148.     bool             GetFirstBand() const;
  149.     void             SetFirstBand(bool firstband);
  150.  
  151.     TRect            GetBandRect() const;
  152.     void             SetBandRect(const TRect& bandrect);
  153.  
  154.     TSize            GetPageSize() const;
  155.     void             SetPageSize(const TSize& pagesize);
  156.     TSize            GetPageSizeInch() const;
  157.     void             SetPageSizeInch(const TSize& pageSizeInch);
  158.  
  159.     virtual void     SetPageSizes(const TPrintDC& dc);
  160.  
  161.   protected:
  162.     virtual void     GetDefaultPrinter();
  163.     virtual void     SetPrinter(const char* driver, const char* device,
  164.                                 const char* output);
  165.  
  166.     virtual bool     ExecPrintDialog(TWindow* parent);
  167.     virtual bool     ExecPageSetupDialog(TWindow* parent);
  168.     virtual TWindow* CreateAbortWindow(TWindow* parent, TPrintout& printout);
  169.  
  170.     // Helper function used by Print
  171.     //
  172.     void             CalcBandingFlags(TPrintDC& prnDC);
  173.  
  174.  
  175.   protected_data:
  176.     int                  Error;       // < 0 if error occurred during print
  177.     TPrintDialog::TData* Data;        // Printer setup information
  178.     TApplication*        Application; // The app owning this printer object
  179.  
  180.     // Variables used by CalcBandingFlags and Print
  181.     //
  182.     bool             UseBandInfo;     // whether to use banding or not
  183.     uint             Flags;           // type of printout
  184.     bool             FirstBand;       // first band?
  185.     TRect            BandRect;        // rectangle size of the band
  186.     TSize            PageSize;        // size of the page
  187.     TSize            PageSizeInch;    // size of an inch on the page
  188.  
  189.   private:
  190.     static HDC UserAbortDC;   // Set by print dialog to prntDC if user cancels
  191.                               // Set to -1 cancels all print jobs
  192.  
  193.     // Hidden to prevent accidental copying or assignment
  194.     //
  195.     TPrinter(const TPrinter&);
  196.     TPrinter& operator =(const TPrinter&);
  197.  
  198.   DECLARE_STREAMABLE(_OWLCLASS, TPrinter, 2);
  199. };
  200.  
  201. //
  202. // class TXPrinter
  203. // ~~~~~ ~~~~~~~~~
  204. // Printer and printout related exceptions
  205. //
  206. class _OWLCLASS_RTL TXPrinter : public TXOwl {
  207.   public:
  208.     TXPrinter(uint resId = IDS_PRINTERERROR);
  209.  
  210. #if defined(BI_NO_COVAR_RET)
  211.     TXBase* Clone();
  212. #else
  213.     TXPrinter* Clone();
  214. #endif
  215.     void Throw();
  216.  
  217.     static void Raise(uint resId = IDS_PRINTERERROR);
  218. };
  219.  
  220. // Generic definitions/compiler options (eg. alignment) following the 
  221. // definition of classes
  222. #include <services/posclass.h>
  223.  
  224. #if defined(BI_NAMESPACE)
  225. } // namespace OWL
  226. #endif
  227.  
  228. //----------------------------------------------------------------------------
  229. // Inline implmentation
  230. //
  231.  
  232. //
  233. // Return the title of the printout.
  234. //
  235. inline const char far* TPrintout::GetTitle() const {
  236.   return Title;
  237. }
  238.  
  239. //
  240. // Return true if banding is desired.
  241. //
  242. inline bool TPrintout::WantBanding() const {
  243.   return Banding;
  244. }
  245.  
  246. //
  247. // Return true if the force all bands.
  248. //
  249. inline bool TPrintout::WantForceAllBands() const {
  250.   return ForceAllBands;
  251. }
  252.  
  253. //
  254. // Return the DC associated with the printout.
  255. //
  256. inline TPrintDC* TPrintout::GetPrintDC() {
  257.   return DC;
  258. }
  259.  
  260. //
  261. // Set the banding flag for the printout.
  262. //
  263. inline void TPrintout::SetBanding(bool banding) {
  264.   Banding = banding;
  265. }
  266.  
  267. //
  268. // Set the force banding flag.
  269. //
  270. inline void TPrintout::SetForceAllBands(bool force) {
  271.   ForceAllBands = force;
  272. }
  273.  
  274. //
  275. // Set the associated DC.
  276. //
  277. inline void TPrintout::SetPrintDC(TPrintDC* dc) {
  278.   DC = dc;
  279. }
  280.  
  281. //
  282. // Retrieve the size of the page.
  283. //
  284. inline TSize TPrintout::GetPageSize() const {
  285.   return PageSize;
  286. }
  287.  
  288. //
  289. // Set the size of the page.
  290. //
  291. inline void TPrintout::SetPageSize(const TSize& pagesize) {
  292.   PageSize = pagesize;
  293. }
  294.  
  295. //
  296. // Return the setup data associated for the printer.
  297. //
  298. inline TPrintDialog::TData& TPrinter::GetSetup() {
  299.   return *Data;
  300. }
  301.  
  302. //
  303. // Set the user abort DC for the printer.
  304. //
  305. inline void TPrinter::SetUserAbort(HDC abortDC) {
  306.   UserAbortDC = abortDC;
  307. }
  308.  
  309. //
  310. // Return the abort DC.
  311. //
  312. inline HDC TPrinter::GetUserAbort() {
  313.   return UserAbortDC;
  314. }
  315.  
  316. //
  317. // Return the error code from the printer.
  318. //
  319. inline int TPrinter::GetError() {
  320.   return Error;
  321. }
  322.  
  323. //
  324. // Set the error code.
  325. //
  326. inline void TPrinter::SetError(int error) {
  327.   Error = error;
  328. }
  329.  
  330. //
  331. // Return the common dialog data associated with the printer.
  332. //
  333. inline TPrintDialog::TData* TPrinter::GetData() {
  334.   return Data;
  335. }
  336.  
  337. //
  338. // Set the common dialog data.
  339. //
  340. inline void TPrinter::SetData(TPrintDialog::TData* data) {
  341.   Data = data;
  342. }
  343.  
  344. //
  345. // Return the application pointer.
  346. //
  347. inline TApplication* TPrinter::GetApplication() {
  348.   return Application;
  349. }
  350.  
  351. //
  352. // Set the application pointer.
  353. //
  354. inline void TPrinter::SetApplication(TApplication* app) {
  355.   Application = app;
  356. }
  357.  
  358. //
  359. // Return true if to use banding information.
  360. //
  361. inline bool TPrinter::GetUseBandInfo() const {
  362.   return UseBandInfo;
  363. }
  364.  
  365. //
  366. // Set the flag indicating whether to use banding information.
  367. //
  368. inline void TPrinter::SetUseBandInfo(bool usebandinfo) {
  369.   UseBandInfo = usebandinfo;
  370. }
  371.  
  372. //
  373. // Return the printer flags.
  374. //
  375. inline uint TPrinter::GetFlags() const {
  376.   return Flags;
  377. }
  378.  
  379. //
  380. // Set the flags for the printer.
  381. //
  382. inline void TPrinter::SetFlags(uint flags) {
  383.   Flags = flags;
  384. }
  385.  
  386. //
  387. // Return true if currently printing the first band.
  388. //
  389. inline bool TPrinter::GetFirstBand() const {
  390.   return FirstBand;
  391. }
  392.  
  393. //
  394. // Set the flag for first band.
  395. //
  396. inline void TPrinter::SetFirstBand(bool firstband) {
  397.   FirstBand = firstband;
  398. }
  399.  
  400. //
  401. // Return the rectangle for the current band.
  402. //
  403. inline TRect TPrinter::GetBandRect() const {
  404.   return BandRect;
  405. }
  406.  
  407. //
  408. // Set the rectangle for the band.
  409. //
  410. inline void TPrinter::SetBandRect(const TRect& bandrect) {
  411.   BandRect = bandrect;
  412. }
  413.  
  414. //
  415. // Return the size of the page.
  416. //
  417. inline TSize TPrinter::GetPageSize() const {
  418.   return PageSize;
  419. }
  420.  
  421. //
  422. // Set the page's size.
  423. //
  424. inline void TPrinter::SetPageSize(const TSize& pagesize) {
  425.   PageSize = pagesize;
  426. }
  427.  
  428. //
  429. // Return the size of an inch the page.
  430. //
  431. inline TSize TPrinter::GetPageSizeInch() const {
  432.   return PageSizeInch;
  433. }
  434.  
  435. //
  436. // Set the size of an inch on the page.
  437. //
  438. inline void TPrinter::SetPageSizeInch(const TSize& pageSizeInch) {
  439.   PageSizeInch = pageSizeInch;
  440. }
  441.  
  442. #endif  // OWL_PRINTER_H
  443.